package org.asiainfo.file.service;

import org.asiainfo.common.core.exception.ServiceException;
import org.asiainfo.common.core.utils.SpringUtils;
import org.asiainfo.file.domain.bo.AttactmentInfoBo;
import org.asiainfo.file.domain.vo.AttactmentInfoVo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 附件上传策略
 *
 * @author dotor-ww
 */
public interface FileStrategy {

    String BASE_NAME = "FileStrategy";

    /**
     * 上传附件
     *
     * @param grantType    上传策略
     * @param attactmentBo 附件信息
     * @param file         文件
     * @return 上传结果
     */
    static AttactmentInfoVo uploadFile(String grantType, AttactmentInfoBo attactmentInfoBo, MultipartFile file) throws Exception {
        String beanName = grantType + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("附件上传策略不正确!");
        }
        FileStrategy instance = SpringUtils.getBean(beanName);
        return instance.uploadFile(attactmentInfoBo, file);
    }

    /**
     * 上传附件
     *
     * @param attactmentBo 附件信息
     * @param file         文件
     * @return 上传结果
     */
    AttactmentInfoVo uploadFile(AttactmentInfoBo attactmentInfoBo, MultipartFile file) throws Exception;
}
